﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV.CvEnum;
using finProj.Entities;

namespace finProj.Gui
{
    public partial class clusterPreview : Form
    {
        private int clusterId;
        private List<Picture> pictures;
        private List<PictureBox> picBoxes; 


        public clusterPreview(int i)
        {
            picBoxes = new List<PictureBox>();
            InitializeComponent();
            LoadImages(i);
        }

        private void LoadImages(int cId)
        {
            this.clusterId = cId;
            pictures = Settings.Instance.clusterManager.clusters[this.clusterId].pictures;
            int y = 5;
            for (int j = 0; j < pictures.Count; j++)
            {
                this.pictureBox1 = new System.Windows.Forms.PictureBox();

                if (j != 0 && j % 3 == 0)
                {
                    y += 160;
                }
                this.pictureBox1.Location = new System.Drawing.Point(10 + 160 * (j % 3), y);


                this.pictureBox1.Name = "pictureBox"+j;
                this.pictureBox1.Size = new System.Drawing.Size(150, 150);
                this.pictureBox1.TabIndex = 0;
                this.pictureBox1.TabStop = false;
                this.pictureBox1.Click+=pictureBox1_Click;
                pictureBox1.Image = pictures[j].origPicture.Resize(150, 150, INTER.CV_INTER_LINEAR).ToBitmap();
                this.panel1.Controls.Add(this.pictureBox1);
                this.picBoxes.Add(pictureBox1);

            }

            this.panel1.AutoScroll = true;

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            PictureBox p = (PictureBox)sender;
            string picboxname = p.Name;

            for (int i = 0; i < this.pictures.Count; i++)
            {
                if (picBoxes[i].Name == picboxname)
                {
                    var imgPrev = new ImagePreview(pictures[i]);
                    imgPrev.Show();

                }
            }


        }

        private void clusterPreview_Load(object sender, EventArgs e)
        {

        }


     }
}
